package get
import (
	"database/sql"
	"fmt"

	"github.com/gin-gonic/gin"
	_ "github.com/lib/pq"
)

func Get_manager(r *gin.Engine) {
	var err error
	var db *sql.DB
	db, err = sql.Open("postgres", "port=5432 user=postgres password=system dbname=databasedesign sslmode=disable")
	var manager_id, manager_password string
	r.GET("/M_login", func(c *gin.Context) {
	// 获取参数
		manager_id = c.Query("managerid")
		manager_password = c.Query(("managerpassword"))
		c.JSON(200, gin.H{
			"managerid":       manager_id,
			"managerpassword": manager_password,
		})
	
		})
	
		fmt.Printf("%s%s", manager_id, manager_password)
	
		r.GET("/M_loginsuccess", func(c *gin.Context) {
			var code, str, sno, password, level string
		code = "0"
	
			if err != nil {
				panic(err)
			}
	
			str = "SELECT password,level FROM student where sno='" + manager_id + "'"
			rows, err := db.Query(str)
			if err != nil {
				panic(err)
			}
			for rows.Next() {
				err = rows.Scan(&password, &level)
				if err != nil {
					panic(err)
				}
			}
			if manager_password == password && level == "0" {
				code = "10"
			}
			fmt.Printf("user:%s%s%s", sno, password, level)
			// 获取参数
			c.JSON(200, gin.H{
				"code":            code,
				"str":             str,
				"managerpassword": manager_password,
				"password":        password,
			})
		})
	}